<?php

namespace forfun\repository;

use forfun\repository\entity\Comment;
use restphp\driver\RestRepository;

class CommentRepository extends RestRepository {
    function __construct() {
        parent::__construct('comment', Comment::class);
    }

    /**
     * 今日评论数.
     * @param $userId
     * @param $kind
     * @param $bizId
     * @return int
     */
    public function countCommentToday($userId, $kind, $bizId) {
        $arrRule = array(
            'user_id'   => $userId,
            'kind'      => $kind,
            'biz_id'    => $bizId,
        );
        return $this->count(array('rule' => $arrRule));
    }

    /**
     * 添加评论.
     * @param $userId
     * @param $kind
     * @param $bizId
     * @param $commentContent
     * @return void
     * @throws \ReflectionException
     */
    public function addComment($userId, $kind, $bizId, $commentContent) {
        $comment = new Comment();
        $comment->setUserId($userId);
        $comment->setKind($kind);
        $comment->setBizId($bizId);
        $comment->setComment($commentContent);
        $comment->setCreateTime(date('Y-m-d H:i:s'));
        $this->save($comment);
    }
}